package com.boarsoft.message.amq.plugin;

import org.apache.activemq.broker.Broker;
import org.apache.activemq.broker.BrokerFilter;
import org.apache.activemq.broker.ProducerBrokerExchange;
import org.apache.activemq.command.Message;
import org.apache.activemq.command.MessageDispatch;

/**
 * 
 * @author Mac_J
 *
 */
public class InterceptorFilter extends BrokerFilter {
	protected InterceptorPlugin plugin;

	public InterceptorFilter(Broker next) {
		super(next);
	}

	public InterceptorFilter(Broker next, InterceptorPlugin plugin) {
		super(next);
		this.plugin = plugin;
	}

	@Override
	public void send(ProducerBrokerExchange pbe, Message am) throws Exception {
		if (plugin.put(am)) {
			super.send(pbe, am);
		}
	}

	@Override
	public void preProcessDispatch(MessageDispatch md) {
		next.preProcessDispatch(md);
	}
}
